package com.licq.ldoc.parser.impl.annotation;

import java.lang.annotation.Annotation;

import net.sf.oval.constraint.DateRange;

import org.apache.commons.lang.StringUtils;

import com.licq.ldoc.domain.Attribute;
import com.licq.ldoc.domain.AttributeType;
import com.licq.ldoc.parser.AnnotationParsee;

public class DateRangeAnnotationParsee extends AnnotationParsee {
	
	public DateRangeAnnotationParsee(AnnotationParsee successor) {
		super(successor);
	}

	@Override
	protected void doParse(Attribute attribute, Annotation annotation) {
		if (AttributeType.isDateType(attribute.getType())) {
			DateRange dateRange = (DateRange) annotation;
			StringBuffer comments = new StringBuffer();
			String min = dateRange.min();
			String max = dateRange.max();
			if (StringUtils.isNotBlank(min) || StringUtils.isNotBlank(max)) {
				comments.append(getText());
				if (StringUtils.isNotBlank(min)) {
					comments.append(">=" + min);
				}
				if (StringUtils.isNotBlank(max)) {
					comments.append((StringUtils.isNotBlank(min) ? " and " : "") + "<=" + max);
				}
			}
			attribute.appendComments(comments.toString());
		}
	}
	
}
